import VueRouter from 'vue-router'
import Vue from 'vue'

const Home = () => import('pages/home/Home')

const About = () => import('../components/About')

const User = () => import('../components/User.vue')

const News = () => import('../components/News.vue')

const Message = () => import('../components/Message.vue')

const Profile = () => import('pages/profile/Profile')

const Cart = () => import('pages/cart/Cart')

const Category = () => import('pages/category/Category')

const Detail = () => import('pages/detail/Detail')





Vue.use(VueRouter)


const routes =[

  {
    path: '/',
    //重定向
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home,
    meta: {
      title: '首页'
    },
    children: [
      {
        path: 'news',
        component: News
      },
      {
        path: 'message',
        component: Message
        
      }
    ]
  },
  {
    path: '/about',
    meta: {
      title: '关于'
    },
    component: About
  },
  {
    path: '/category',
    meta: {
      title: '分类'
    },
    component: Category
  },
  {
    path: '/cart',
    meta: {
      title: '购物车'
    },
    component: Cart
  },
  {
    path: '/user/:userId',
    meta: {
      title: '用户'
    },
    component: User
  },
  {
    path: '/profile',
    meta: {
      title: '档案'
    },
    component: Profile
  },
  {
    path: '/detail/:id',
    meta: {
      title: '详情页'
    },
    component: Detail
  }

]

const router = new VueRouter({
  routes,
  mode: 'history',
  linkActiveClass: 'shixiaobai'
})



router.beforeEach((to,from,next) => {
  document.title = to.matched[0].meta.title
  next()
})

export default router